<?php
/*
	@
	\<\s*?(\w+)((?:\b(?:\'[^\']*\'|"[^"]*"|[^\>])*)?)\>
	((?:(?>[^\<]*)|(?R))*)
	\<\/\s*?\\1(?:\b[^\>]*)?\>
	|\<\s*(\w+)(\b(?:\'[^\']*\'|"[^"]*"|[^\>])*)?\/?\>
	@uxis  
  
	$pattern = "/<([\w]+)([^>]*?) (([\s]*\/>)| (>((([^<]*?|<\!\-\-.*?\-\->)| (?R))*)<\/\\1[\s]*>))/xsm";
	b(?>m|(?R))*e
 * */


class BlockPattern extends Pattern {
	
	public function __construct(){
		
		$class      = '\w+';
		$id         = '\w+';
		$var        = '\w+';  
		$beginmark  = '\{';
		$endmark    = '\}';
		$openmark   = '[\[\|]';
		$closemark  = '[\]\/\|]';
		$properties = '(?:\'[^\']*\'|"[^"]*"|[^}])*';
		$argument   = $openmark.'\s*(?:'.$properties.')?';
		$beginblock = $beginmark.'\s*('  .$class.  ')?\s*('  .$id.  ')\s*('.$argument.')?' . $endmark;
		$endblock   = $beginmark. $closemark .'\s*?\\2(?:\b[^'.$endmark.']*)?'.$endmark;
		$block      = '((?:(.*)|(?R))*)';
		#$block      = "((?:( ? >)|(?R))*)";
		$normal     = $beginblock . $block . $endblock;
		$short      = $beginmark.'\s*(?:('.$class.'\s+)?)('.$id.')\s*'.'('.$openmark.'\s*'.$properties.')?'.$closemark.'?\s*'.$endmark;
		$tag        = $beginmark.'\s*\$?('.$var.')\s*'.$endmark;
		$pattern    = '/'.$normal.'|'.$short.'|'.$tag.'/Umxs';
		
		#$properties = '\|\s*(?:\'[^\']*\'|)*';
		$b  = "{\s*(\w+)?\s*(\w+)\s*($argument)?\s*(?:$closemark)?\s*}";
		$m  = "[^{]+";
		$e  = "{\s*$closemark\s*\\2\s*}"; 
		$r  = "$b((?>$m|(?R))+)?$e|$tag";
		#$pattern = "/$r/xms";
		#$pattern = "/{\s*([\w]+)?\s*([\w]+)([^}]*?) \s*(([\s]*$closemark\s*})| (}((([^{]*?|{\!\-\-.*?\-\-})| (?R))*){\s*$closemark\\2[\s]*}))|$tag/xsm";
		$this->pattern = $pattern;
	}
}//end class

?>